<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
	<div id="app-content">
		<table id="content_table">
			<tbody>
				{{^widgetList}}
					该应用还没有绑定模块，请先到应用管理进行模块绑定
				{{/widgetList}}
				{{#widgetList}}
				<tr>
					<td><span style="line-height: 25px;" class="label label-info">
							{{name}}</span></td>
					<td class="operation" id="{{id}}"></td>
				</tr>
				{{/widgetList}}
			</tbody>
		</table>
	</div>
	<div id="operationList" style="display: none">
		{{#operationList}} <input type="checkbox" value="{{id}}" /><span>
			{{name}}</span> {{/operationList}}
	</div>
	</div>
</body>
</html>
<script type="text/javascript">
	$(function() {
		var roleID = "{{roleID}}";
		var appId = "{{appId}}";
		var operation = $('#content_table tr');
		var htmString = $('#operationList').html();
		$(operation).each(function(index) {
			$(this).children("td:eq(1)").html(htmString);
		});
		findPrivileges(roleID, appId);
		//获取角色已经拥有的操作权限
		function findPrivileges(roleID, appId) {
			var data = "roleID=" + roleID + "&appId=" + appId;
			$.ajax({
				url : "privileges",
				type : 'get',
				data : data,
				dataType : 'json',
				success : setPrivilegeCheckBox,
				error : function() {
					bootbox.alert("服务器繁忙，请稍后再试！");
				}
			})
		}

		/*
		 * 填充权限设置窗口中的checkbox
		 */
		function setPrivilegeCheckBox(privilegeList) {
			for (i in privilegeList) {
				var opIds = privilegeList[i].operation_IDs;//操作表集合
				for (p in opIds) {
					var cb = $('td[id="' + privilegeList[i].module_ID + '"]');
					var input = $(cb).find("input");//获取操作项checkbox对象集合
					input.each(function(index) {
						if (input[index].value == opIds[p])
							input[index].checked = true;
					});
				}
			}
		}
	})
</script>
